package cn.training.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.training.bean.UserBean;
import cn.training.service.HelloWorldService;


@Controller("HelloWorldController")
@RequestMapping("/")
public class HelloWorldController {

	@Autowired
	HelloWorldService helloWorldService;
	
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
        return "helloWorld";
    }
    
    @RequestMapping(value = "/init", method = RequestMethod.POST,params="serch")
    public String initLogin(UserBean userBean, Model model){
        	List<UserBean> result = helloWorldService.searchUser(userBean);
        	model.addAttribute("List", result);
            return "xdw";
    }
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(UserBean userupdate, Model model) {
    	
    	int update = helloWorldService.updateUser(userupdate);
    	if(update==1){
    		
    	model.addAttribute("userBean", userupdate);
    	model.addAttribute("message","OK");
        return "mess";
    	}
    	else{
    		model.addAttribute("message","FALSE");
    		return "mess";
    	}
        
    }
    @RequestMapping(value = "/deleteUser", method = RequestMethod.GET)
    public String delete(UserBean userBean, Model model){
        	int result = helloWorldService.deleteUser(userBean);
        	List<UserBean> result1 = helloWorldService.searchUser(userBean);
        	model.addAttribute("List", result1);
            return "xdw";
    }
    
}
